package wh.bos.service.take_delivery.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wh.bos.dao.take_delivery.PromotionRepository;
import wh.bos.domain.take_delivery.PageBean;
import wh.bos.domain.take_delivery.Promotion;
import wh.bos.service.take_delivery.PromotionService;

@Service
@Transactional
public class PromotionServiceImpl implements PromotionService{
	
	@Autowired
	private PromotionRepository promotionRepository;
	@Override
	public void save(Promotion model) {
		promotionRepository.save(model);
	}
	@Override
	public Page<Promotion> findPageDate(Pageable pageable) {
		return promotionRepository.findAll(pageable);
	}
	
	@Override
	public PageBean<Promotion> findPageDate1(int page, int rows) {
		Pageable pageable = new PageRequest(page-1, rows);
		Page<Promotion> pageDate = promotionRepository.findAll(pageable);
		
		//封装到PageBean
		PageBean<Promotion> pageBean = new PageBean<>();
		pageBean.setPageDate(pageDate.getContent());
		pageBean.setTotalCount(pageDate.getTotalElements());
		return pageBean;
	}


}
